#pragma once

#include <boost/asio.hpp>
#include <boost/noncopyable.hpp>
#include <vector>

#include <IIOServicePool.hpp>

class IIoServiceFactory;
class IWork;

class IOServicePool : public IIOServicePool, public boost::noncopyable
{
public:
	IOServicePool(IIoServiceFactory& ioServicesFactory, const std::size_t poolSize);

	virtual void run() override;
	virtual void stop() override;
	virtual IIOService& getIoService() override;
	virtual ~IOServicePool();

private:
	typedef std::shared_ptr<IIOService> IoServicePtr;
	typedef std::shared_ptr<IWork> WorkPtr;

	IIoServiceFactory& m_ioServicesFactory;

	/// The pool of io_services.
	std::vector<IoServicePtr> m_ioServices;

	/// The work that keeps the io_services running.
	std::vector<WorkPtr> m_works;

	/// The next io_service to use for a connection.
	std::size_t m_nextIoService;

};

